/**
 * Description...
 *
 * @author     mole <mole1230@gmail.com>
 * @version    $Id: init.js 85 2011-01-07 08:40:13Z mole1230 $
 */
jQuery(function($) {
	$('table.post input:text').addClass('text');
	$('table.list tbody tr').click(function(e) {
		$('td', this).toggleClass('selected');
	});
	$("table.list tbody a[target='_blank']").click(function(e) {
		$(this).closest('tr').find('td').addClass('selected');
		e.stopPropagation();
	});
	$('table.list thead input:checkbox').click(function(e) {
		$nodes = $(this).closest('table.list').find('tbody input:checkbox');
		checked= this.checked;
		$nodes.each(function(i, el) {
			this.checked = checked;
		});
	});
	$('table.list thead a.del-all').click(function(e) {
		alert('未实现');
		return false;
	});
	$('table.list tbody a.del-single').click(function(e) {
		var $this = $(this);
		$.ajax({
			url: $this.attr('href'),
			cache: false,
			dataType: 'json',
			beforeSend: function(xhr) {
				if ($this.data('__AJAX-UNCOMPLETE__') || !confirm(App.t('确定删除？'))) {
					return false;
				}
				
				$this.data('__AJAX-UNCOMPLETE__', true);
				return true;
			},
			complete: function(xhr, status) {
				$this.data('__AJAX-UNCOMPLETE__', false);
			},
			success: function(json, status) {
				if (/^A[0-9]{5}/.test(json.code)) {
					$this.closest('tr').remove();
				} else {
					alert(App.t(json.code));
				}
			},
			error: function(xhr, status, e) {
				alert(App.t('服务器内部错误'));
				App.log(arguments);
			}
		});
		return false;
	});
});